package com.wxf.listener;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;

/**
 * 模拟消费者 nack 后消息成为死信的情况
 */
public class DLEListener implements ChannelAwareMessageListener {
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        try {
            System.out.println(new String(message.getBody(), "utf-8"));
            int i = 3 / 0;
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
        }catch (Exception e){
            channel.basicNack(message.getMessageProperties().getDeliveryTag(),true,false);
        }
    }
}
